<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="../common/header.jsp"%>
<div class="clearfix"></div>
<div class="row">
  <div class="col-md-12 col-sm-12 col-xs-12">
    <div class="x_panel">
      <div class="x_title">
        <h2>修改APP <i class="fa fa-user"></i></h2>
        <div class="clearfix"></div>
      </div>
      <div class="x_content">
        <div class="clearfix"></div>
        <form class="form-horizontal form-label-left" action="doUpdate" method="post" enctype="multipart/form-data">
          
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="appName">软件名称 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
              <input id="appName" class="form-control col-md-7 col-xs-12"
               data-validate-length-range="20" data-validate-words="1" name="appName" required="required" placeholder="请输入软件名称" type="text" value="${appInfo.appName }">
            </div>
            <span>${errors.appName}</span>
          </div>
          
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="versionName">版本名称 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
              <input id="versionName" class="form-control col-md-7 col-xs-12" 
               data-validate-length-range="20" data-validate-words="1" name="versionName"  required="required" placeholder="请输入版名称" type="text" value="${appInfo.versionName }">
            </div>
            <span>${errors.versionName}</span>
          </div>
          
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="versionCode">版本号 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
              <input id="versionCode" class="form-control col-md-7 col-xs-12" 
               data-validate-length-range="20" data-validate-words="1" name="versionCode"  required="required" placeholder="请输入版号" type="text" value="${appInfo.versionCode}">
            </div>
            <span>${errors.versionCode}</span>
          </div>
          
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12"  for="appType">所属平台 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
              <select name="appType" id="appType" class="form-control" required="required">
                  <option value="1">android应用</option>
                  <option value="2">ios应用</option>
              </select>
            </div>
          </div>
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="categoryLevel1">一级分类 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
              <select name="categoryLevel1" id="categoryLevel1" class="form-control" required="required" <%--onchange="getLevel2()"--%>>
              	<option value="">请选择一级分类</option>
                  <option value="1">应用</option>
                  <option value="2">游戏</option>
              </select>
            </div>
          </div>
          
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12"  for="categoryLevel2">二级分类 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
              <select name="categoryLevel2" id="categoryLevel2" class="form-control" required="required">
              </select>
            </div>
          </div>
          
          <div class="item form-group">
            <label class="control-label col-md-3 col-sm-3 col-xs-12" for="imgUrl">LOGO图片 <span class="required">*</span></label>
            <div class="col-md-6 col-sm-6 col-xs-12">
            <img src="${ctx}/statics/images/${appInfo.imgUrl}" width="100px" height="100px" alt="invalid imgUrl">
            <input type="file" class="form-control col-md-7 col-xs-12" name="img" id="imgUrl"/>
            ${fileError }
            </div>
          </div>
          <input name="userId" value="${user.userId }" type="hidden"/>
          <input name="appId" value="${appInfo.appId }" type="hidden"/>
          <input name="imgUrl" value="${appInfo.imgUrl}" type="hidden"/>
          <input name="size" value="${appInfo.size}" type="hidden"/>
          <input name="status" value=${appInfo.status} type="hidden" id="status"/>
          <input name="download" value="${appInfo.download}" type="hidden" id="download"/>
          <input name="createTime" value="<fmt:formatDate value='${appInfo.createTime }' pattern='yyyy/MM/dd HH:mm:ss'/>" type="hidden" id="createTime"/>
          <div class="ln_solid"></div>
          <div class="form-group">
            <div class="col-md-6 col-md-offset-3">
              <button id="send" type="submit" class="btn btn-success">保存</button>
              <button id="back" type="button" class="btn btn-primary" onclick="back1()">返回</button>
              <br/><br/>
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

<%@include file="../common/footer.jsp"%>
<script>
    var c1=$("#categoryLevel1");
    var c2=$("#categoryLevel2");
    function getLevel2() {
        $.getJSON(
            "${ctx}/app/getLevel2",
            {parentId:c1.val()},//携带的参数
            function(data){
                c2.html("<option>--请选择--</option>");
                //使用each函数遍历返回的list数据
                // index：元素下标，element:元素
                $(data).each(function (index,element) {
                    //将元素内容取出，拼接层option标签，添加到二级分类<select>中
                    c2.append("<option value='"+element.id+"'>"+element.categoryName+"</option>");
                });
                c2.val(${appInfo.appCategory2.id});//选中之前查询的二级分类
            });
    }
    c1.change(function () {
        getLevel2();
    });
    $(function () {
       $("#appType").val(${appInfo.appType});
        c1.val(${appInfo.appCategory1.id});//选中之前搜索的一级分类
        //重新获取二级分类
        if(c1.val()!=""){
            getLevel2();
        }
    });
    function back1(){
        window.location.href = "list";
    };
</script>
<%--<script src="${pageContext.request.contextPath }/statics/localjs/appinfoadd.js"></script>--%>
